package com.focustech.crov.persist.mybatis.generator;

import java.io.IOException;
import java.io.InputStream;
import java.sql.SQLException;

import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.exception.InvalidConfigurationException;
import org.mybatis.generator.exception.XMLParserException;
import org.mybatis.generator.internal.DefaultShellCallback;

/**
 * mybatis持久层自动生成代码人口
 * @author wangjinping
 * 
 */
public class GeneratorHelper {

	private static final String MYBATIS_GENERATOR_CONFIG_FILE_PATH = "/context/mybatis/generate/generatorConfig.xml";

	public static void main(String[] args) throws IOException,
			XMLParserException, InvalidConfigurationException, SQLException,
			InterruptedException {
		InputStream mybatisGeneratorConfigFileIs = GeneratorHelper.class
				.getResourceAsStream(MYBATIS_GENERATOR_CONFIG_FILE_PATH);
		ConfigurationParser configurationParser = new ConfigurationParser(null,
				null);
		Configuration configuration = configurationParser
				.parseConfiguration(mybatisGeneratorConfigFileIs);
		DefaultShellCallback defaultShellCallback = new DefaultShellCallback(
				true);
		MyBatisGenerator myBatisGenerator = new MyBatisGenerator(configuration,
				defaultShellCallback, null);
		myBatisGenerator.generate(null);
	}
}